<?php 
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../DAO/CategoryDAO.php';
class CategoryService
{
	public function create(BaseContext $context, ServiceResult $result, CategoryDomain $categoryDomain)
	{
		try
		{
			$categoryDAO = new CategoryDAO($context);
			$categoryDAO->create($categoryDomain);
			$result->setSuccess();
		}
		catch (Exception $e)
		{
			$context->logException($e);
			$result->setException($e);
		}
	}

	public function update(BaseContext $context, ServiceResult $result, CategoryDomain $categoryDomain)
	{
		try
		{
			$categoryDAO = new CategoryDAO($context);
			$categoryDAO->update($categoryDomain);
			$result->setSuccess();
		}
		catch (Exception $e)
		{
			$context->logException($e);
			$result->setException($e);
		}
	}

	public function delete(BaseContext $context, ServiceResult $result, $oid)
	{
		try
		{
			$categoryDAO = new CategoryDAO($context);
			$categoryDAO->delete($oid);
			$result->setSuccess();
		}
		catch (Exception $e)
		{
			$context->logException($e);
			$result->setException($e);
		}
	}

	public function findByOid(BaseContext $context, ServiceResult $result, $oid)
	{
		try
		{
			$categoryDAO = new CategoryDAO($context);
			$categoryDomain = $categoryDAO->findByOid($oid);
			$result->setSuccess();
			return $categoryDomain;
		}
		catch (Exception $e)
		{
			$context->logException($e);
			$result->setException($e);
		}
	}

	public function findAll(BaseContext $context, ServiceResult $result)
	{
		try
		{
			$categoryDAO = new CategoryDAO($context);
			$categoryDomainArr = $categoryDAO->findAll();
			$result->setSuccess();
			return $categoryDomainArr;
		}
		catch (Exception $e)
		{
			$context->logException($e);
			$result->setException($e);
		}
	}

}
?>